package com.toe.admin.controller;

import com.toe.commodity.service.CommodityClassesTypeService;
import com.toe.common.restful.JsonResult;
import com.toe.pojo.entity.commodity.CommodityClassesType;
import com.toe.pojo.vo.commodity.CommodityClassTypeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/costClassType")
@Api(tags = "付费课程类型管理")
public class CostClassTypeController {
    @DubboReference
    private CommodityClassesTypeService dubboCostClassType;

    @ApiOperation(value = "查询所有付费课程的类型")
    @GetMapping("/query")
    public JsonResult<List<CommodityClassTypeVO>> selectCostClassType() {
        List<CommodityClassTypeVO> list = dubboCostClassType.getCommodityClassType();
        return JsonResult.ok(list);
    }

    @ApiOperation(value = "添加付费课程类型")
    @PostMapping("/add")
    public JsonResult<Void> addCostClassType(String classTypeName) {
        dubboCostClassType.addNewCommodityClassType(classTypeName);
        return JsonResult.ok();
    }

    @ApiOperation(value = "删除付费课程类型")
    @PostMapping("/delete")
    public JsonResult<Void> removeCostClassType(Long id) {
        dubboCostClassType.deletedCommodityClassType(id);
        return JsonResult.ok();
    }

    @ApiOperation(value = "修改付费课程类型")
    @PostMapping("/update")
    public JsonResult<Void> updateCostClassType(@RequestBody CommodityClassesType commodityClassesType) {
        dubboCostClassType.updateCommodityClassTypeName(commodityClassesType);
        return JsonResult.ok();
    }


}
